# Builds the doc of all the Projects that the test depend upon
doc_test_build_chain:
	$(show) ""                                                           ; \
	echo "********************************************* "                ; \
	echo "Building the documentation of all the Projects that the test for Project $(project) depend on" ; \
	$(make_cmd) test_chain chain_target=doc_build                        ; 

# Builds the doc of all the Projects that the test depend upon
doc_test_clean_chain:
	$(show) ""                                                           ; \
	echo "********************************************* "                ; \
	echo "Cleaning the documentation of all the Projects that the test for Project $(project) depend on" ; \
	$(make_cmd) test_chain chain_target=doc_clean                        ; 

# Generates the Doxygen file for the project
generate_doxygen: doc_prj_deps
	$(show)                                                              ; \
	d=$(dir_doc)/Doxygen                                            ; \
	rm -f "$$d"                                                          ; \
	echo "OUTPUT_DIRECTORY       = $(dir_doc)" > "$$d"  ; \
	echo "HTML_OUTPUT            = $(dir_doc)/html"  >> "$$d" ; \
	echo "INPUT                  = $(dir_src) $(dir_inc) $(dir_test) " >> "$$d" ; \
	echo "INCLUDE_PATH           = $(dir_src) $(dir_inc) $(dir_test) " >> "$$d" ; \
	echo "PROJECT_NAME           = $(project)"                  >> "$$d" ; \
	echo "IMAGE_PATH             = $(dir_doc)"  >> "$$d"           ; \
	echo "GENERATE_TAGFILE       = $(project).tag" >> "$$d"              ; \
	echo "EXAMPLE_PATH           = $(dir_test)" >> "$$d"            ; \
	echo "STRIP_FROM_PATH        = $(dir_src)" >> "$$d"                 ; \
	echo "EXCLUDE                = $(dir_src)/prj_deps.h $(dir_src)/dummy.h">> "$$d" ; \
	refs=`echo "$(prj_depends)" | tr -s " "`                             ; \
	refs=`echo "$$refs" | tr [:space:] "-"`                              ; \
	if [ ! -z $$refs ]; then                                               \
		cont_ref=1                                                   ; \
		ref=`echo $$refs | cut -d '-' -f$$cont_ref`                  ; \
		while [ ! -z "$$ref" ]; do                                     \
			tag_file="$$tag_file $(dir_docs)/$$ref/$$ref.tag=../$$ref" ; \
			cont_ref=`echo $$cont_ref+1 | bc`                    ; \
			ref1=`echo $$refs | cut -d '-' -f$$cont_ref`         ; \
			if [ "$$ref" = "$$ref1" -a $$cont_ref -eq 2 ] ; then   \
				ref=""                                       ; \
			else                                                   \
				ref=$$ref1                                   ; \
			fi                                                   ; \
		done                                                         ; \
	fi                                                                   ; \
	test_refs=`echo "$(test_depends)" | tr -s " "`                       ; \
	test_refs=`echo "$$test_refs" | tr [:space:] "-"`                    ; \
	if [ ! -z $$test_refs ]; then                                          \
		test_cont_ref=1                                              ; \
		test_ref=`echo $$test_refs | cut -d '-' -f$$test_cont_ref`   ; \
		while [ ! -z "$$test_ref" ]; do                                \
			test_tag_file="$$test_tag_file $(dir_docs)/$$ref/$$test_ref.tag=../$$test_ref" ; \
			test_cont_ref=`echo $$test_cont_ref+1 | bc`          ; \
			test_ref1=`echo $$test_refs | cut -d '-' -f$$test_cont_ref` ; \
			if [ "$$test_ref" = "$$test_ref1" -a $$test_cont_ref -eq 2 ] ; then   \
				test_ref=""                                  ; \
			else                                                   \
				test_ref=$$test_ref1                         ; \
			fi                                                   ; \
		done                                                         ; \
	fi                                                                   ; \
	echo "TAGFILES               = 	$$tag_file $$test_tag_file" >> "$$d" ; \
	cat "$(dir_tool)/aux_files/Doxygen_part"  >> "$$d"                   ;


# Generates a jpg file with a graph showing the dependencies of this project 
# to other projects
doc_prj_deps:
	$(show) ""                                                           ; \
	tmp="$(dir_src)/tmp"                                                 ; \
	arq="$(dir_src)/prj_deps.h"                                          ; \
	rm -f "$$tmp"                                                        ; \
	rm -f "$$arq"                                                        ; \
	echo "/// @page prj_deps_$(project) Project Dependencies"  > "$$tmp" ; \
	echo "/// @section deps_graph_$(project) Graph " >> "$$tmp"          ; \
	echo "///"  >> "$$tmp"                                               ; \
	echo "/// @dot " >> "$$tmp"                                          ; \
	echo "/// digraph $(project) {" >> "$$tmp"                           ; \
	aux="$(project) $(prj_depends)"                                      ; \
	refs=`echo "$$aux" | tr -s " "`                                      ; \
	refs=`echo "$$refs" | tr [:space:] "-"`                              ; \
	if [ ! -z $$refs ]; then                                               \
		cont_ref=1                                                   ; \
		ref=`echo $$refs | cut -d '-' -f$$cont_ref`                  ; \
		while [ ! -z "$$ref" ]; do                                     \
			if [ "$$ref" != "$(project)" ]; then                   \
				echo "/// $(project) -> $$ref;" >> "$$tmp"   ; \
			fi                                                   ; \
			info=`make verbose=$(verbose)                          \
				cpu_os_comp=$(cpu_os_comp)                     \
				target=$(target) project="$$ref"               \
				M_version=$(M_version)                         \
				m_version=$(m_version)                         \
				build_number=$(build_number) prj_info`       ; \
			prod_type=`echo "$$info" | grep product_type | cut -d '=' -f 2`  ; \
			if [ $$prod_type = "lib'" ]; then                      \
				echo  "/// $$ref [shape=box,label=\"$$ref\\\nlibrary\"];" >> "$$tmp"; \
			else                                                   \
				if [ $$prod_type = "pgm'" ]; then              \
					echo  "/// $$ref [shape=box,label=\"$$ref\\\nprogram\"];" >> "$$tmp" ; \
				else                                           \
					echo  "/// $$ref [shape=box,label=\"$$ref\\\njust copy\"];" >> "$$tmp" ; \
				fi                                           ; \
			fi                                                   ; \
			cont_ref=`echo $$cont_ref+1 | bc`                    ; \
			ref1=`echo $$refs | cut -d '-' -f$$cont_ref`         ; \
			if [ "$$ref" = "$$ref1" -a $$cont_ref -eq 2 ] ; then   \
				ref=""                                       ; \
			else                                                   \
				ref=$$ref1                                   ; \
			fi                                                   ; \
		done                                                         ; \
	fi                                                                   ; \
	echo "/// }" >> "$$tmp"                                              ; \
	echo "/// @enddot" >> "$$tmp"                                        ; \
	echo "/// " >> "$$tmp"                                               ; \
	cat "$$tmp" | sed 's/\./_/g' > "$$arq" 2> /dev/null                  ; \
	rm -f "$$tmp"                                                        ; 





#                           PUBLIC

#@public@|doc_build|Builds the Documentation of the Project
#@public_detailed@|doc_build|Syntax: 'make project=<project-name> [verbose=0/1]  doc_build
#@public_detailed@|doc_build|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
doc_build :  generate_doxygen 
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo "Building documentation for $(project)"                         ; \
	cd $(dir_doc)                                                        ; \
	doxygen Doxygen                                                      ; 


# setup

#@public@|doc_build_chain|Builds the Documentation of the Project
#@public_detailed@|doc_build_chain|Syntax: 'make project=<project-name> [verbose=0/1]  doc_build_chain
#@public_detailed@|doc_build_chain|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
doc_build_chain : doc_test_build_chain
	$(show) ""                                                           ; \
	echo -n "Building doc of all the Projects that $(project) "          ; \
	echo "depend on"                                                     ; \
	$(make_cmd) chain chain_target=doc_build                             ; \
	$(make_cmd) doc_build                                                ;



#@public@|doc_clean|Cleans the Documentation of the Project
#@public_detailed@|doc_clean|Syntax: 'make project=<project-name> [verbose=0/1]  doc_clean
#@public_detailed@|doc_clean|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
doc_clean : setup
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo "Cleaning doc for $(project) "                                  ; \
	rm -rf $(dir_doc)/*                                                  ; \
	rm -f $(dir_doc)/Doxygen                                             ; \
	rm -f $(dir_doc)/html

#@public@|doc_clean_chain|Cleans the Documentation of the Project, and the Documentation of all the Projects that this depends one
#@public_detailed@|doc_clean_chain|Syntax: 'make project=<project-name> [verbose=0/1]  doc_clean_chain
#@public_detailed@|doc_clean_chain|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
doc_clean_chain : 
	$(show) ""                                                           ; \
	echo "**************************************** "                     ; \
	echo -n "Cleaning doc of all the Projects that $(project) "          ; \
	echo "depend on"                                                     ; \
	$(make_cmd) chain chain_target=doc_clean                             ; \
	$(make_cmd) doc_clean                                                ;
